﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PMS.IRepository;
using PMS.IServices;
using PMS.Models.Base;
using PMS.Repository;
using PMS.Utils;

namespace PMS.Services
{
    public class BasePowerService : IBasePowerService
    {
        IBasePowerRepository _basePowerRepository = new BasePowerRepository();

        #region 公共方法

        public int Add(BasePower user)
        {
            return _basePowerRepository.Add(user);
        }

        public int Edit(BasePower user)
        {
            return _basePowerRepository.Edit(user);
        }

        public BasePower Dtl(int id)
        {
            return _basePowerRepository.Dtl(id);
        }

        public bool IsExists(int id)
        {
            return _basePowerRepository.IsExists(id);
        }

        public int Delete(int id, string deleteBy)
        {
            Hashtable ht = new Hashtable { { "ParentId", id } };
            List<int> Ids = _basePowerRepository.GetList(ht)?.Select(x => x.Id).ToList();
            if (Ids != null)
            {
                _basePowerRepository.Delete(Ids.ToArray(), deleteBy);
            }
            return _basePowerRepository.Delete(id, deleteBy);
        }

        public int Delete(int[] ids, string deleteBy)
        {
            return _basePowerRepository.Delete(ids, deleteBy);
        }

        public List<BasePower> GetList()
        {
            return _basePowerRepository.GetList();
        }

        #endregion

        public List<BasePower> GetList(Hashtable ht)
        {
            return _basePowerRepository.GetList(ht);

        }

        public int GetMaxId()
        {
            return _basePowerRepository.GetMaxId();
        }
    }
}